package scigest.command;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class BaseCommand {
	
	protected List<BaseCommand> cmdRegistry = new LinkedList<BaseCommand>();
	private Map<String,String> cmdMap= new HashMap<String,String>();
	private static final Logger logger = LoggerFactory.getLogger(BaseCommand.class);
	
	public boolean register(BaseCommand bc) {
		String cmdKey = bc.getCmdKey();
		String cmdHelp = bc.getSummary();
		
		if (cmdMap.keySet().contains(bc.getCmdKey())) {
			logger.error("Command key[ {} ] exists , registration fails", bc.getCmdKey());
			return false;
		}
		cmdMap.put(cmdKey, cmdHelp);
		cmdRegistry.add(bc);
		return true;
	}
	
	public void unregister(String key) {
	}
	
	public abstract boolean exec(String[] args);
	public abstract String getSummary();
	public abstract String getUsageDetails();
	public abstract String getCmdKey();
	
}
